﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArithmeticDemo
{
    public class LeeCode278
    {
        public void Start() {
            Console.WriteLine(FirstBadVersion(6));
        }
        public int FirstBadVersion(int n) {
            int left = 1;
            int right = n;
            int i = 1;
            while (left < right) {
                i = left + (right - left) / 2;
                if (IsBadVersion(i)) {
                    right = i ;
                } else {
                    left = i + 1;
                }

            }
            return left;
        }
        public bool IsBadVersion(int version) {
            if (version == 1) {
                return true;
            }
            return false;
        }
    }
}
